package wiki.kaizen.cloud.plugin.spring.scan.aspect;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import wiki.kaizen.cloud.plugin.spring.scan.compent.AsyncProxyCompent;
import wiki.kaizen.cloud.plugin.spring.util.IpUtil;


/**
 * 日志系统 切面处理类
 *
 * */
@Aspect
@Component
@Slf4j
public class LogAspect {

    private final AsyncProxyCompent asyncProxy;

    public LogAspect(AsyncProxyCompent asyncProxy) {
        this.asyncProxy = asyncProxy;
    }

    @Pointcut("@annotation(wiki.kaizen.cloud.plugin.spring.scan.annotation.Log)")
    public void logPointCut(){}

    @Around("logPointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {

        long startTime = System.currentTimeMillis();
        //方法执行结果
        Object proceed = point.proceed();

        long time = System.currentTimeMillis() - startTime;

        asyncProxy.logHandler(point,time, IpUtil.getIp());
        return proceed;
    }


}
